import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout/Layout.vue'
import Home from '@/views/Home/Home.vue'
// 路由配置与v2是一致的

// 路由设计：哪个url地址--->哪个页面[路由嵌套]
const routes = [
  {
    path: '/', // 直接访问
    name: 'layout',
    component: Layout,
    children: [
      {
        path: '', // /#/ path为空，默认展示这个组件
        name: 'home',
        component: Home
      },
      {
        path: '/category/:id', // /#/category
        name: 'category',
        component: () => import('@/views/Category/Category.vue')
      },
      {
        path: '/goods/:id', // /#/goods/4221341
        name: 'goods',
        component: () => import('@/views/Goods/Goods.vue')
      },
      {
        path: '/cart',
        name: 'cart',
        component: () => import('@/views/Cart/Cart.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login/Login.vue')
  },

  {
    path: '/settle',
    name: 'settle',
    component: () => import('@/views/Settlement/Settlement.vue')

  },
  {
    path: '/pay',
    name: 'pay',
    component: () => import('@/views/Pay/Pay.vue')
  }

  // {
  //   path: '/',
  //   name: 'home',
  //   component: HomeView
  // },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]
// v2: new VueRouter()
// v3：createRouter
const router = createRouter({
  history: createWebHashHistory(), // hash模式的路由
  routes
})

export default router
